<?php

namespace app\common\business;

use app\common\lib\Arr;
use app\common\lib\Time;
use app\common\model\mysql\SystemCategory;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Exception;
use think\Model;

class Statistics
{
    /**
     * 获取顶部统计
     * @return array
     * @throws DataNotFoundException
     * @throws DbException
     * @throws ModelNotFoundException
     */
    public function getTopNum(){
        $noticeBis = new Notice();
        $swiperBis = new Banner();
        $linksBis = new Links();
        $fileBis = new Images();

        $condition = [
            ['status','=',config("status.mysql.table_normal")]
        ];

        //全部
        $noticeNums = $noticeBis->getListByWhere($condition,0,0,'id');
        $swiperNums = $swiperBis->getListByWhere($condition,0,0,'id');
        $linksNums = $linksBis->getListByWhere($condition,0,0,'id');
        $fileNums = $fileBis->getListByWhere($condition,0,0,'id');

        //当月新增时间条件
        $month_start = strtotime(date("Y-m-01"));
        $month_end = strtotime("+1 month -1 seconds", $month_start);
        $map = [
            ['create_time','between',[$month_start,$month_end]],
            ['status','=',config("status.mysql.table_normal")]
        ];
        $addNoticeNums = $noticeBis->getListByWhere($map,0,0,'id');
        $addSwiperNums = $swiperBis->getListByWhere($map,0,0,'id');
        $addLinksNums = $linksBis->getListByWhere($map,0,0,'id');
        $addFileNums = $fileBis->getListByWhere($map,0,0,'id');

        $result = [
            'addNoticeNums'=>count($addNoticeNums),
            'addSwiperNums'=>count($addSwiperNums),
            'addLinksNums'=>count($addLinksNums),
            'addFileNums'=>count($addFileNums),
            'noticeNums'=>count($noticeNums),
            'swiperNums'=>count($swiperNums),
            'linksNums'=>count($linksNums),
            'fileNums'=>count($fileNums),
        ];
        return $result;
    }
}
